<template>
  <div id="app">
    
      <router-view></router-view>
    
  </div>
</template>

<script>
//rem适配
new function (){
  var _self = this;
  _self.width = 750;
  _self.fontSize = 100;
  _self.widthProportion = function(){
    var p = (document.body&&document.body.clientWidth||document.getElementsByTagName("html")[0].offsetWidth)/_self.width;
    return p>1?1:p;
  };
  _self.changePage = function(){
     document.getElementsByTagName("html")[0].setAttribute("style","font-size:"+_self.widthProportion()*_self.fontSize+"px !important");
  }
  _self.changePage();
  window.addEventListener("resize",function(){_self.changePage();},false);


};

export default {
  name: 'App',
  data(){
    return{
      
    }
  },
  watch:{
    //页面切换效果
    '$route':{
      handler(to, from) {
        document.title = this.$route.name;
        this.$nextTick(() => {
          this.fixWeChatViewPort()
        });
      },
      immediate: false,
      deep: true
    }
  },
  created() {
    this.setWxConfig();
  },
  mounted(){
  },
  methods:{
    //微信初始化
    setWxConfig:function() {
      var self = this;
      var url = location.href.split('#')[0]; //获取锚点之前的链接
      var request = {
          url: url
      };
      this.Ajax.post('DataService/WxInterfaceRegister',request).then(function(resp) {
        // alert("resp","微信接口")
        if (resp.code == "SUCC") {
            var data = JSON.parse(resp.data);
            //开始注册wx
            // console.log(data,"##")
            self.jWeixin.config({
                debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
                appId: data.appid, // 必填，公众号的唯一标识
                timestamp: data.timestamp, // 必填，生成签名的时间戳
                nonceStr: data.noncestr, // 必填，生成签名的随机串
                signature: data.signature, // 必填，签名，见附录1
                jsApiList: [
                    "scanQRCode",
                    "getLocation",
                    "getLocalImgData",
                    "previewImage",
                    "chooseImage",
                    "getLocation",
                    "openLocation",
                    "uploadImage",
                    "downloadImage",
                    "onMenuShareAppMessage",
                    "onMenuShareQQ",
                    "showMenuItems",
                    "menuItem:share:appMessage",
                    "menuItem:share:qq",
                    "hideOptionMenu"
                ] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
            });
            self.jWeixin.hideOptionMenu();
        }
      });
    },
    fixWeChatViewPort(){
      let inputs = document.getElementsByTagName('input'),
          textareas = document.getElementsByTagName('textarea');
      if(inputs.length > 0 || textareas.length > 0){
        let ti = makeArray(inputs),
            ta = makeArray(textareas),
            args = ti.concat(ta);
        for (let x of args) {
          x.addEventListener('blur',() => {
            fix();
          })
        }
      }
      function fix(){          
        setTimeout(() => {
          const scrollHeight = document.documentElement.scrollTop || document.body.scrollTop || 0;
          window.scrollTo(0, Math.max(scrollHeight - 1, 0));
        }, 100);
      }

      function makeArray(obj){ 
        return Array.prototype.slice.call(obj,0); 
      } 
    },
  }
}
</script>

<!-- 公共样式引入 -->
<style lang="less">
@import url('./style/common.less');
</style>
